class HttpCla {
	public constructor() {
	}


	private static _me: HttpCla;
	public static get me() {
		if (HttpCla._me == null)
			HttpCla._me = new HttpCla();
		return HttpCla._me;
	}

	private _call: Function = null;
	private _thisobje: any = null;
	private request: egret.HttpRequest;
	public getHttp(_url: string, callBack: Function, thisobje: any) {
		_url="http://203.107.1.33/100000/d?host=www.aliyun.com";
		console.log("发送http协议：" + _url);
		this._call = callBack;
		this._thisobje = thisobje;
		if (this.request == null) {
			this.request = new egret.HttpRequest();

		}
		//this.request.setRequestHeader("Host","203.107.1.33");
		//this.request.setRequestHeader("Host","http://www.xiaoyougames.com/");
		
		
		this.request.responseType = egret.HttpResponseType.TEXT;
		this.request.open(_url, egret.HttpMethod.GET);
		this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.request.send();
		this.request.addEventListener(egret.Event.COMPLETE, this.onGetComplete, this);
		//request.addEventListener(egret.Event.COMPLETE, this.onGetComplete, this);

		this.request.addEventListener(egret.IOErrorEvent.IO_ERROR, this.onGetIOError, this);
		this.request.addEventListener(egret.ProgressEvent.PROGRESS, this.onGetProgress, this);
	}

	private onGetComplete(event: egret.Event): void {
		var request = <egret.HttpRequest>event.currentTarget;
		//console.log("HTTP返回 : ", request.response);
		// var responseLabel = new egret.TextField();
		// responseLabel.size = 18;
		// responseLabel.text = "GET response: \n" + request.response.substring(0, 50) + "...";
		// this.addChild(responseLabel);
		// responseLabel.x = 50;
		// responseLabel.y = 70;
		this._call(JSON.parse(request.response), this._thisobje);
	}
	private onGetIOError(event: egret.IOErrorEvent): void {
		console.log("get error : " + event);
		EffectUtils.showTips("http errro:" + event, 1);

	}
	private onGetProgress(event: egret.ProgressEvent): void {
		//console.log("get progress : " + Math.floor(100 * event.bytesLoaded / event.bytesTotal) + "%");
	}
}